package com.bdqn.entity.responseDate.cart;

import com.bdqn.entity.responseDate.pmsProduct.PmsSkuDto;
import com.bdqn.entity.util.DateUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 承载购物车信息
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class OmsCartDto implements Serializable,Comparable<OmsCartDto> {
    private Long userId;
    private Long spuId;
    private Long skuId;
    /**
     * 商品标题
     */
    private String title;
    /**
     * 商品默认图片URL
     */
    private String picUrl;
    /**
     * 库存信息
     */
    private String stockMsg;
    /**
     * 单价
     */
    private BigDecimal unitPrice;
    /**
     * 单位
     */
    private String unit;
    /**
     * 商品数量
     */
    private Integer num;
    /**
     * 每类商品的总价
     */
    private BigDecimal price;

    private String addTime;

    //创建购物车 Dto
    public OmsCartDto(PmsSkuDto pmsSkuDto, int num, Long userId) {
        this.userId = userId;
        this.skuId = pmsSkuDto.getId();
        this.spuId = pmsSkuDto.getSpuId();
        this.title = pmsSkuDto.getTitle();
        this.picUrl = pmsSkuDto.getPicUrl();
        this.unitPrice = pmsSkuDto.getPrice();
        this.unit = pmsSkuDto.getUnit();
        this.num = num;
        this.price = unitPrice.multiply(new BigDecimal(num));
        this.addTime = DateUtils.format(new Date(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }


    /**
     * 用来排序的方法
     * @param cartDto
     * @return
     */
    @Override
    public int compareTo(OmsCartDto cartDto) {
        //按添加时间降序
        return cartDto.getAddTime().compareTo(this.getAddTime());
    }
}
